package com.hefeng.unit.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hefeng.unit.domain.GyDeviceReport;
import com.hefeng.unit.mapper.GyDeviceReportMapper;
import com.hefeng.unit.service.GyDeviceReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class GyDeviceReportServiceImpl extends ServiceImpl<GyDeviceReportMapper, GyDeviceReport> implements GyDeviceReportService {
    @Autowired
    public  GyDeviceReportMapper gyDeviceReportMapper;
    @Override
    public List<GyDeviceReport> getReportList(String userId) {
        //1. 构建动态查询条件
        LambdaQueryWrapper<GyDeviceReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GyDeviceReport::getUserId,userId);
       // queryWrapper.ge( GyDeviceReport::getReportTime, DateUtil.offsetWeek(new Date(), -1));
        queryWrapper.orderByDesc(GyDeviceReport::getReportTime);
        List<GyDeviceReport> list=gyDeviceReportMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public Page<GyDeviceReport> paginQuery(String userId, long current, long size) {
        //1. 构建动态查询条件
        LambdaQueryWrapper<GyDeviceReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GyDeviceReport::getUserId,userId);
        queryWrapper.orderByDesc(GyDeviceReport::getReportTime);
        //2. 执行分页查询
        Page<GyDeviceReport> pagin = new Page<>(current , size);
        Page<GyDeviceReport> selectResult = this.page(pagin,queryWrapper);
        //3. 返回结果
        return pagin;
    }
}
